#ifndef _UPS_H_
#define _UPS_H_

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

/** error code define */
#define UPS_SUCCESS 0
#define UPS_EFAIL (-1)
#define UPS_EMEMO (-2)
#define UPS_EPARA (-3)
#define UPS_ERWIO (-4)

#define UPS_DISK_DIR "log/param"
#define UPS_DEF_DIR "set_0"
#define UPS_CUR_DIR "set_1"
#define UPS_DISK_DEF UPS_DISK_DIR"/"UPS_DEF_DIR
#define UPS_DISK_CUR UPS_DISK_DIR"/"UPS_CUR_DIR

#define UPS_LOG_CONF "common/zlog.conf"
#define UPS_LOG_CAT  "ups"

enum disk_file_type
{
	EFILE_DEF = 1,
	EFILE_CUR,
	EFILE_META
};

typedef int (*get_func)(void *conf, void *data,int size);
typedef int (*set_func)(void *conf, void *data,int size);

typedef struct param_desc
{
	char mname[32]; /* module name */
	int  module; /* module id */
	get_func get;
	set_func set;
} sparam_desc_t;

typedef struct param_info
{
	int module;
	void *conf;
	int size;
	int persist;
} sparam_info_t;

typedef struct param_meta
{
	int valid;
	int consist; /** consistency with set1 disk file */
} sparam_meta_t;

/** the ups entry in the RAM,used in the inter */
typedef struct param_unit
{
	pthread_rwlock_t lock;
	sparam_desc_t desc;
	sparam_meta_t meta;
	void *conf;
	int size;
} sparam_unit_t;

/******************* Funnction Declaration ***************/
int ups_init_env(const char *project);

int ups_init_conf(sparam_desc_t desc, void *deconf, int size);

int ups_get_conf(sparam_info_t *info, void *data,int size);

int ups_set_conf(sparam_info_t info, void *data,int size);

/** exit to free malloced memory*/
int ups_exit_conf(sparam_desc_t desc);

int ups_exit_env(void);

#endif

